﻿function Get-TSMVolume {    
    <#
        .SYNOPSIS
            Get TSM volumes
                    
        .DESCRIPTION
            The Get-TSMVolume returns volumes
                        
        .PARAMETER Volume
            The volume to search
            
        .PARAMETER StoragePool
            The storage pool to search
            
        .PARAMETER DeviceClass
            The device class to search
            
        .PARAMETER Access
            The access to search

        .PARAMETER Status
            The status to search

        .EXAMPLE
            Get-TSMVolume

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 09/01/2015

    #>
    [CmdletBinding()]
    Param(
        [Parameter(Position = 0)]
        $Volume,
        
        [Parameter(Position = 1)]
        $StoragePool,
        
        [Parameter(Position = 2)]
        $DeviceClass,
        
        [Parameter(Position = 3)]
        [ValidateSet("READWRITE","READONLY","UNAVAILABLE","OFFSITE","DESTROYED")]
        $Access,
        
        [Parameter(Position = 4)]
        [ValidateSet("ONLINE","OFFLINE","EMPTY","PENDING","FILLING","FULL")]
        $Status
    )
    
    $whereProps = @()
    $whereProps += [PSCustomObject]@{ "Column" = "VOLUME_NAME";   "Operator" = "LIKE"; "Value" = $Volume }
    $whereProps += [PSCustomObject]@{ "Column" = "STGPOOL_NAME";  "Operator" = "LIKE"; "Value" = $StoragePool }
    $whereProps += [PSCustomObject]@{ "Column" = "DEVCLASS_NAME"; "Operator" = "LIKE"; "Value" = $DeviceClass }
    $whereProps += [PSCustomObject]@{ "Column" = "ACCESS";        "Operator" = "LIKE"; "Value" = $Access }
    $whereProps += [PSCustomObject]@{ "Column" = "STATUS";        "Operator" = "LIKE"; "Value" = $Status }

    $query = Format-TSMQuery -Table "VOLUMES" -Where $whereProps -OrderBy "STGPOOL_NAME,VOLUME_NAME"
    $result = Invoke-TSMCommand -Command $query
    
    $defaultDisplaySet = 'VOLUME_NAME','STGPOOL_NAME','DEVCLASS_NAME','EST_CAPACITY_MB','PCT_UTILIZED','STATUS'
    $typeDefinitions = @{
                        "EST_CAPACITY_MB" = [Int32]
                        "PCT_UTILIZED"    = [Int32]
                        "PCT_RECLAIM"     = [Int32]
                        "NUM_SIDES"       = [Int32]
                        "TIMES_MOUNTED"   = [Int32]
                        "WRITE_PASS"      = [Int32]
                        "WRITE_ERRORS"    = [Int32]
                        "READ_ERRORS"     = [Int32]
                        "LAST_WRITE_DATE" = [DateTime]
                        "LAST_READ_DATE"  = [DateTime]
                        "CHG_TIME"        = [DateTime]
                        }

    return Format-TSMData -Data $result -TypeDefinitions $typeDefinitions -DefaultDisplaySet $defaultDisplaySet
}